package com.SoapClasses;


import java.io.IOException;
import java.net.SocketTimeoutException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;
import com.Managers.LogManagerClass;


public class SoapPost_Likes {

    private static final String TAG = "SoapPost_Likes";

    SoapSerializationEnvelope envelope;

    PropertyInfo pi;

    SoapObject Request;

    public String addLike(String data[]) {

        String METHOD_NAME = "newLike";
        String SOAP_ACTION = "http://ShareUp.com/newLike";
        //
        Request = new SoapObject(SoapUtil.NAMESPACE, METHOD_NAME);
        //
        //
        String info = "";
        for (int i = 0; i < data.length; i++) {
            info += data[i] + "@";
        }
        PropertyInfo pi = new PropertyInfo();
        pi = new PropertyInfo();
        pi.setName("data");
        pi.setValue(info);
        pi.setType(String.class);
        //
        Request.addProperty(pi);
        //
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);
        HttpTransportSE httpTransport = new HttpTransportSE(SoapUtil.URL, SoapUtil.TIMEOUT);
        //
        Object response = null;
        try {

            httpTransport.call(SOAP_ACTION, envelope);
            response = envelope.getResponse();
        }
        catch (SocketTimeoutException x) {
            Log.e(TAG + ": ", x.getMessage());
            LogManagerClass.writeLog(TAG + ": " + x.getMessage());
            return "-10";
        }
        catch (SoapFault e) {
            StackTraceElement[] stack = e.getStackTrace();
            String Trace = " ";
            for (StackTraceElement line : stack) {
                Trace += line.toString();
            }
            Log.e(TAG + ": ", Trace);
            LogManagerClass.writeLog(TAG + ": " + Trace);
        }
        catch (IOException x) {
            Log.e(TAG + ": ", x.getMessage());
            LogManagerClass.writeLog(TAG + ": " + x.getMessage());
            return x.getMessage();
        }
        catch (XmlPullParserException x) {
            Log.e(TAG + ": ", x.getMessage());
            LogManagerClass.writeLog(TAG + ": " + x.getMessage());
            return x.getMessage();
        }
     
        return response.toString();
    }

    public String deleteLike(String[] data) {

        String METHOD_NAME = "deleteLike";
        String SOAP_ACTION = "http://ShareUp.com/deleteLike";
        //
        Request = new SoapObject(SoapUtil.NAMESPACE, METHOD_NAME);
        //
        //
        String info = "";
        for (int i = 0; i < data.length; i++) {
            info += data[i] + "@";
        }
        PropertyInfo pi = new PropertyInfo();
        pi = new PropertyInfo();
        pi.setName("data");
        pi.setValue(info);
        pi.setType(String.class);
        //
        Request.addProperty(pi);
        //
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);
        HttpTransportSE httpTransport = new HttpTransportSE(SoapUtil.URL);
        //
        Object response = null;
        try {

            httpTransport.call(SOAP_ACTION, envelope);
            response = envelope.getResponse();
        }
        catch (Exception x) {
            response = x.toString();
            Log.e(TAG + ": ", x.getMessage());
            LogManagerClass.writeLog(TAG + ": " + x.getMessage());
        }

        return response.toString();
    }
}
